/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package mx.generarHorario.itschapala.vista;

import java.util.List;
import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import mx.generarhorario.itschapala.bl.salonBlLocal;
import mx.generarhorario.itschapala.modelo.Salon;

/**
 *
 * @author RaygozaL
 */
@ManagedBean
@SessionScoped
public class salonBean {
    @EJB
    private salonBlLocal salonBl;
    
    
    //----------------variables
    private  Salon salon;
   private List<Salon> lista;
   private String accion;
   //------------contructor

   
    public salonBean() {
        salon= new Salon();
        
    }
    
   //-----------get y set
    public List<Salon> getLista() {
        lista=salonBl.getAll();
        return lista;
    }
    public Salon getSalon() {
        return salon;
    }

    public void setSalon(Salon salon) {
        this.salon=salon;
    }
    
    
  ///----------------acciones
    
    public String procesarAccion(){
        
       if (accion.equals("Nuevo")) {
            salonBl.register(salon);

        } else {
            if (accion.equals("Editar")) {
                salonBl.modify(salon);

            } else{
                if(accion.equals("Eliminar")){
                salonBl.delete(salon);
                }
            }
            
        }
        accion = "";
        return "Salon";
    }

//    public void prepararNuevo(ActionEvent evt){
//        
//        author=new Autor();
//    accion="Nuevo";
//    }
    
    public String prepararNuevo(){
        
        salon=new Salon();
        accion="Nuevo";
    return "ProfesorCrearEditar";
    }
    
    public void prepararEditar(javax.faces.event.ActionEvent evt){
       int index = Integer.parseInt(evt.getComponent().getClientId().split(":")[2]);
        System.out.println("el numero es " + index);
        accion = "Editar";
        salon = lista.get(index);

    }
    public void prepararEliminar(javax.faces.event.ActionEvent evt) {

        int index = Integer.parseInt(evt.getComponent().getClientId().split(":")[2]);
        System.out.println("el numero es " + index);
        accion = "Eliminar";
       salon = lista.get(index);


    } 
    
    
}
